//
//  GHPushLargeVC.m
//  VideoPic
//
//  Created by GH on 16/3/31.
//  Copyright © 2016年 apple. All rights reserved.
//

#import "GHPushLargeVC.h"
#import <YYWebImage.h>

@interface GHPushLargeVC ()
@property (nonatomic ,retain)UIScrollView *scroll;

@end

@implementation GHPushLargeVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor blackColor];
//    CGRect frame = [self.arrFrame[self.index] CGRectValue];
    
    self.scroll = [[UIScrollView alloc] initWithFrame:self.view.bounds];
    [self.view addSubview:self.scroll];
    
    self.scroll.contentSize = CGSizeMake(self.arrUrl.count * self.view.frame.size.width, 0);
    CGFloat height = [self.arrHeight[self.index] floatValue] *([UIScreen mainScreen].bounds.size.width - 40) / [self.arrWidth[self.index] floatValue];
    
    NSString *strsize = self.arrFrame[self.index] ;
    CGPoint size = CGPointFromString(strsize);

    for (int i = 0; i < self.arrUrl.count; i++) {
        
        UIImageView *image = [YYAnimatedImageView new];
        if (self.index == i) {
            
            image.frame = CGRectMake(size.x +self.view.frame.size.width *i,size.y, (self.view.frame.size.width - 60) /3, (self.view.frame.size.width - 60) /3);
        }else {
        
            image.frame = CGRectMake(self.view.frame.size.width * i, self.view.center.y /2, self.view.frame.size.width - 20 , height);

        
        }
        
        image.tag = 20 +i;

        image.yy_imageURL = [NSURL URLWithString:self.arrUrl[i]];
        [self.scroll addSubview:image];
        image.backgroundColor = [UIColor redColor];
    }
    
    [self.scroll setContentOffset:CGPointMake(self.index * self.view.frame.size.width, 0)];
    self.scroll.showsHorizontalScrollIndicator = NO;
    self.scroll.showsVerticalScrollIndicator = NO;
    self.scroll.pagingEnabled = YES;
    
    
    
    [UIView animateWithDuration:0.6 animations:^{
        
        
        
        UIImageView * image = [self.view viewWithTag:20 + self.index];
        
        image.frame = CGRectMake(self.view.frame.size.width * self.index, self.view.center.y/ 2, self.view.frame.size.width - 20 , height);
        
    }];
    

    
    
    UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleClick:)];
    //    tapGesture.numberOfTouchesRequired = 1;
    [self.scroll addGestureRecognizer:tapGesture];
    
}



- (void)handleClick:(UITapGestureRecognizer *)tap {
    
    [UIView animateWithDuration:0.3 animations:^{
        
        
        
  self.index = self.scroll.contentOffset.x/ self.view.frame.size.width;
        
        
        
        UIImageView * image = [self.view viewWithTag:20 + self.index];

        
        NSLog(@"---%f",self.scroll.contentOffset.x);
        NSString *strsize = self.arrFrame[self.index] ;
        CGPoint size = CGPointFromString(strsize);
        
//        if (self.index <= 2) {
//            
//        }else if (self.index >2 && self.index < 5) {
//            self.index = self.index -3;
//        }else {
//            self.index = self.index - 6;
//        
//        }
        NSLog(@"%ld",(long)self.index);
        
        image.frame = CGRectMake(size.x + self.view.frame.size.width * self.index, size.y, (self.view.frame.size.width - 60) /3, (self.view.frame.size.width - 60) /3);
        
        NSLog(@"%@",NSStringFromCGRect(image.frame));
    } completion:^(BOOL finished) {
//
        [[NSNotificationCenter defaultCenter] postNotificationName:@"tabBarhiddenmany" object:nil];
        self.navigationController.navigationBar.hidden = NO;
        [self.navigationController popViewControllerAnimated:NO];
        
    }];
    
    
    
}



- (void)dealloc {
    
    NSLog(@"移除");
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"tabBarhidden" object:nil];
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
